<?php

namespace App\Http\Middleware;

use App\Models\Player;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class CheckPlayer
{
    public function handle(Request $request, Closure $next): Response
    {
        $player = $request->player;

        if ($player instanceof Player && !$player->isShowable()) {
            abort(404, '选手不存在');
        }

        return $next($request);
    }
}
